package com.jian.java;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author Jiange
 * @create 2021-09-19-14:55
 */
public class MyStudy {
    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new org.apache.activemq.ActiveMQConnectionFactory("" +
                "tcp://192.168.1.1:61616");
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("queue");
        MessageProducer producer = session.createProducer(queue);
        producer.send(session.createTextMessage("建哥最帅"));
        MapMessage mapMessage = session.createMapMessage();
        mapMessage.setString("name","李子建");
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        producer.send(mapMessage);

        Queue queue1 = session.createQueue("queue");
        MessageConsumer consumer = session.createConsumer(queue1);
        consumer.setMessageListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {

            }
        });

        //先设置持久化  再设置
        Topic topic = session.createTopic("jian");
        TopicSubscriber subscriber = session.createDurableSubscriber(topic, "remake...");
        MessageProducer producer1 = session.createProducer(topic);
        producer1.setDeliveryMode(2);
    }
}
